/**
 * @description Model Manifest
 *
 * @author Xiongmao
 */

var db = require('../db');

module.exports = db.model('Type', {
    tableName: 'types',
    hasTimestamps: true,

    parent() {
        return this.belongsTo('Type', 'parent_id');
    },
    nums() {
        return this.hasMany('Ticket', 'type_id')
        .query(qb => {
            qb.count('id as count');
            qb.select('type_id', 'status');
            qb.orderBy('status');
            qb.groupBy('status', 'type_id');
        });
    }
}, {
    OFFLINE: 0,
    ONLINE: 1,
});
